/**
 * Created by songj on 2015/12/11.
 */
define(['angular',
    'framework/msg/GillionMsgModule',
    'framework/dataGrid/DataGridModule',
    'framework/pagination/GillionPaginationModule',
    'framework/datasource/DataSourceModule',
    'framework/dropdown/GillionDropdownModule',
    'framework/date/DateModule',
    'angular-underscore'
], function (angular) {
    var module = angular.module('AssetController',
        ['GillionMsgModule', 'DataGridModule', 'GillionPaginationModule',
            'DataSourceModule', 'DateModule', 'GillionDropdownModule'])
        .controller('AssetController', ['$scope', 'GillionMsgService', 'Resource',
                function ($scope, GillionMsgService, Resource) {
                    $scope.expectAsset = GillionMsgService.getInputData();

                    var expectAssetResource = Resource("/grule-manager/unitcases/assets/:id", {
                        id: "@id"
                    });

                    $scope.submit=function(){
                        $scope.AssertForm.verify().then(function(){
                            var expectAsset = $scope.expectAsset;
                            if(expectAsset.id) {
                                expectAssetResource.update(expectAsset, function () {
                                    GillionMsgService.close();
                                });
                            }else{
                                expectAssetResource.create(expectAsset, function () {
                                    GillionMsgService.close();
                                });
                            }
                        });
                    }

                    $scope.cancel = function(){
                        GillionMsgService.close();
                    }
                }
            ]
        );

    module.config(['$locationProvider', function($locationProvider) {
        $locationProvider.html5Mode(true);
    }]);
    return module;
});
